package com.xsmart.oa.services.mall.mymenu;

import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.dao.mall.mymenu.UserMsgManagerDao;
import com.xsmart.common.entity.user.InfsUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserMsgManagerService {

    @Autowired
    UserMsgManagerDao userMsgManagerDao;

    public ResponseBean updateUserMsg(RequestBean requestBean) {
        String userPicture = requestBean.getRequestParamString("url");
        Integer userId = requestBean.getRequestParamInteger("userId");
        String userName = requestBean.getRequestParamString("userName");
        Integer sex = requestBean.getRequestParamInteger("sex");
        String birthday = requestBean.getRequestParamString("birthday");
        String mobilePhone = requestBean.getRequestParamString("mobilePhone");
        String nickName = requestBean.getRequestParamString("nickName");
        String officePhone = requestBean.getRequestParamString("officePhone");
        String homePhone = requestBean.getRequestParamString("homePhone");
        String qq = requestBean.getRequestParamString("qq");
        if (birthday!=null){
            birthday = birthday.substring(0,10);
        }
        InfsUsers infsUser = new InfsUsers();
        infsUser.setUserId(userId);
        infsUser.setUserName(userName);
        infsUser.setSex(sex);
        infsUser.setBirthday(birthday);
        infsUser.setMobilePhone(mobilePhone);
        infsUser.setNickName(nickName);
        infsUser.setOfficePhone(officePhone);
        infsUser.setHomePhone(homePhone);
        infsUser.setQq(qq);
        infsUser.setUserPicture(userPicture);
        int num = userMsgManagerDao.updateUserMsg(infsUser);
        ResponseBean responseBean = requestBean.getResponseBean();
        if(num>0){
            responseBean.setResult(ResultConstant.SUCCESS);
        }else{
            responseBean.setResult(ResultConstant.ERROR);
        }
        return responseBean;
    }


}
